package api

import (
	"django_blog_gin/internal/dto"
	accountRepo "django_blog_gin/internal/repository"
	"django_blog_gin/internal/response"
	"django_blog_gin/internal/svc"
	"django_blog_gin/internal/utils"

	"github.com/gin-gonic/gin"
)

type GetUserDetail struct {
	svcCtx *svc.ServiceContext
}

func NewGetUserDetail(svcCtx *svc.ServiceContext) gin.HandlerFunc {
	return GetUserDetail{svcCtx: svcCtx}.GetUserDetail
}

func (i GetUserDetail) GetUserDetail(c *gin.Context) {
	var req dto.GetUserDetailReq
	if !utils.ValidateJsonBody(c, &req) {
		return
	}
	accountRepo := accountRepo.NewAccount(i.svcCtx)
	accountBlogUser, err := accountRepo.IdGetUser(req.Id)
	if err != nil {
		c.JSON(response.CodeFail, gin.H{"error": err.Error()})
		return
	}
	c.JSON(response.CodeSuccess, gin.H{"data": accountBlogUser})
}
